package com.example.demo.springboot.mqclient.consumer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * FunOutConsumer:模拟消费者[只需要知道生产者推送到的交换机就行]
 * 这个模式生产投递到各个交换机方便,但是消费者都可以收到消息,其实不方便对接收方的控制
 *
 * @author zhangxiaoxiang
 * @date 2020/11/16
 */
@Component
@Slf4j
public class FanOutConsumer {

    @RabbitListener(bindings = {
            @QueueBinding(
                    exchange = @Exchange(type = ExchangeTypes.FANOUT, name = MqConsumerConstant.FANOUT_CALLLOG_EXCHANGE),
                    value = @Queue(name = MqConsumerConstant.FANOUT_CRM_CALLLOG_QUEUE)
            )
    })
    public void crmListener(String msg) {
        log.info("crm系统收到外呼话单回调[执行业务逻辑]:{}", msg);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    exchange = @Exchange(type = ExchangeTypes.FANOUT, name = MqConsumerConstant.FANOUT_CALLLOG_EXCHANGE),
                    value = @Queue(name = MqConsumerConstant.FANOUT_ZHIYU_CALLLOG_QUEUE)
            )
    })
    public void zhiYuListener(String msg) {
        log.info("zhiYu系统收到外呼话单回调[执行业务逻辑]:{}", msg);
    }
}
